More problems from the Colombian National Contest 2010. Only two to go.
[and.git] / 10432 - Polygon inside a circle / 10432.cpp
blobef8faaf9f1966819960c018b1d88004c250b854b
1 #include <iostream>
2 #include <cstdlib>
3 #include <cmath>
4 #include <cassert>
6 using namespace std;
8 const double pi = 2*acos(0);
10 int main(){
11 double r;
12 int n;
13 while (cin >> r >> n){
14 assert(r > 0);
15 assert(n > 2);
16 double anguloInterno = (pi - (2*pi / n)); // 180 - (360/n)
17 anguloInterno /= 2;
18 //cout << anguloInterno * 180.0 / pi << endl;
19 double anguloFaltante = pi - 2*anguloInterno;
20 //cout << anguloFaltante * 180.0 / pi << endl;
21 double b = r * sin(anguloFaltante) / sin(anguloInterno);
22 //cout << b << endl;
23 double h = r*r - b*b/4;
24 h = sqrt(h);
25 double resultado = b*h/2 * n;
26 printf("%.3f\n", resultado);
28 return 0;